<template>
<view>
<form @submit="fromsubmit">
    <view class="modle">
    店铺名称：
    <input class="modle_right" name="nickname" placeholder="请输入店铺名称" placeholderStyle="color: #9295A8;" type="text" :value="detail.nickname">
    </view>
    <view @tap="selectbrand" class="modle">
    咨询电话：
    <button @getphonenumber="getPhoneNumber" class="modle_btn" open-type="getPhoneNumber">电话授权</button>
        <input @blur="checkPhone" class="modle_right" maxlength="11" name="phone" placeholder="请输入咨询电话" placeholderStyle="color: #9295A8;" type="number" :value="phone">
    </view>
    <view class="modle">
    看车地址：
        <button @tap="tomap" class="modle_btn">获取位置</button>
        <input class="modle_right" name="address" placeholder="请输入试车地址" placeholderStyle="color: #9295A8;" type="text" :value="address?address:''">
    </view>
    <view v-if="detail.is_vip==1">
        <view class="modle" style="border-bottom:0">
    店铺logo
    <button @tap="addlogo" class="modle_btn"> 编辑logo</button>
        </view>
        <view>
            <view class="shangchuan_view_index" v-if="head_image">
                <image class="shangchuan_view_index" :src="head_image"></image>
            </view>
            <view @tap="addlogo" class="shangchuan_view_index" v-else>
                <image class="shangchuan_view_index" src="/static/pages/image/tianjiantp_btn.png" style="border-radius: 0;"></image>
            </view>
        </view>
    </view>
    <view v-if="detail.is_vip==1">
        <view class="modle" style="border-bottom:0">
    店铺封面
    <button @tap="addimg" class="modle_btn">编辑封面</button>
        </view>
        <view>
            <view class="shangchuan_view" v-if="temp">
                <image class="shangchuan_Img" :src="temp"></image>
            </view>
            <view @tap="addimg" class="shangchuan_view" v-else>
                <image class="shangchuan_Img" src="/static/pages/image/tianjiantp_btn.png"></image>
            </view>
        </view>
    </view>
    <button class="bufa_btn" form-type="submit">保存</button>
</form>
<!--<import src="/pages/alert/index.wxml"></import>-->
<block data-type="template" data-is="alert" data-attr="isShow:isShow">
    <view class="wx_dialog_container" :hidden="!isShow">
        <view class="wx-alert-mask"></view>
        <view class="wx-alert-dialog">
            <view class="wx-alert-dialog-title">尊敬的用户</view>
            <view class="wx-alert-dialog-content">尚未获取到您的用户信息，较多功能无法体验，请允许获取用户信息</view>
            <view class="wx-alert-dialog-footer">
                <button @tap="hideDialog" class="wx-alert-dialog-btn">拒绝</button>
                <button @getuserinfo="updateUserInfo" class="wx-alert-dialog-btn" open-type="getUserInfo">允许</button>
            </view>
        </view>
    </view>
</block>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
      phone: "",
      address: "",
      temp: "",
      store_img: "",
      head_image: "",
      detail: ""
    };
  },

  components: {},
  props: {},
  onLoad: function (a) {
    var e = this;
    app.globalData.util.request({
      url: "entry/wxapp/Api",
      data: {
        m: "monai_market",
        r: "me.info",
        uid: wx.getStorageSync("uid")
      },
      success: function (a) {
        e.setData({
          detail: a.data.data,
          phone: a.data.data.phone,
          address: a.data.data.address,
          temp: a.data.data.store_img,
          head_image: a.data.data.head_image,
          store_img: a.data.data.store_img
        });
      }
    });
  },
  methods: {
    getPhoneNumber: function (a) {
      var e = this;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          r: "sale.index.userphone",
          m: "monai_market",
          iv: a.detail.iv,
          encryptedData: a.detail.encryptedData
        },
        cachetime: "0",
        success: function (a) {
          e.setData({
            phone: a.data.data
          });
        }
      });
    },
    checkPhone: function (a) {
      var e = a.detail.value;
      if (!/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/.test(e)) return wx.showToast({
        title: "手机号有误！",
        icon: "none",
        duration: 1500
      }), !1;
    },
    tomap: function () {
      var e = this;
      wx.chooseLocation({
        success: function (a) {
          e.setData({
            address: a.address
          });
        }
      });
    },
    addimg: function (a) {
      var e = this;
      app.globalData.upimgs({
        scannums: 1,
        filename: "cars",
        success: function (a) {
          e.setData({
            temp: a[0].all,
            store_img: a[0].short
          });
        }
      });
    },
    addlogo: function (a) {
      var e = this;
      app.globalData.upimgs({
        scannums: 1,
        filename: "logo",
        success: function (a) {
          e.setData({
            head_image: a[0].all
          });
        }
      });
    },
    fromsubmit: function (a) {
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_market",
          r: "me.updateinfo",
          uid: wx.getStorageSync("uid"),
          nickname: a.detail.value.nickname,
          phone: a.detail.value.phone,
          address: a.detail.value.address,
          store_img: this.store_img,
          head_image: this.head_image
        },
        success: function (a) {
          wx.showToast({
            title: "修改成功",
            icon: "success",
            duration: 2e3,
            complete: function () {
              wx.navigateBack({
                delta: 1
              });
            }
          });
        }
      });
    },

    selectbrand() {
      console.log("占位：函数 selectbrand 未声明");
    }

  }
};
</script>
<style>
@import "./index.css";
</style>